home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / rexx / loadold.mbrx < prev    next >
Text File  |  1996-07-23  |  2KB  |  103 lines

  1. /*
  2. ** LoadOld.mbrx Version 1.1
  3. ** By Tom Bampton
  4. **
  5. ** © 1996 Eden Software
  6. **
  7. ** Loads an old MegaBook v2.0/2.1 file.
  8. ** If you wish to convert files, its probably better to use the FileConvert
  9. ** programs instead of this script. This is just an example! Interestingly
  10. ** enuff, this is an almost direct conversion of the C code used in
  11. ** MegaBook v2.0/2.1 to load files. 
  12. **
  13. ** If you run this from the CLI with RX then you can give it a filename
  14. ** argument. If an argument isn't found, you'll get a file requester.
  15. **
  16. ** From MegaBook v3.1, this script may also be used from the menu option
  17. ** 'Load Old...'
  18. */
  19.  
  20. /* The path to MegaBook in case it isn't running */
  21. MegaBookPath = 'MegaBook3:MegaBook'
  22.  
  23. /* To get newlines in requesters */
  24. LF = '0a'x
  25.  
  26. parse arg File
  27.  
  28. /* Check if MegaBook is running, if not, run it */
  29. if ~show('P', 'MEGABOOK.01') then do
  30.     address command
  31.     'run >nil: ' MegaBookPath
  32.     /* Wait for the ARexx port */
  33.     do 5 while ~show('P', 'MEGABOOK.01')
  34.         'sys:rexxc/waitforport MEGABOOK.01'
  35.     end
  36. end
  37.  
  38. address 'MEGABOOK.01'
  39. options results
  40.  
  41. /* If no command line arguments, open the file requester */
  42. if File = '' then do
  43.     SelectFile 'Select MegaBook v2.0 file ...'
  44.     File = result
  45.     if RC = 5 then exit
  46. end
  47.  
  48. if Open(fp, File, 'r') then do
  49.     
  50.     head = readln(fp)
  51.     
  52.     /* Check the header for the filetype */
  53.     if head ~= 'PB20' then do
  54.         Request 'Not a MegaBook 2.0/2.1 file' GADS 'Sorry'
  55.         call Close(fp)
  56.         exit
  57.     end
  58.     
  59.     /* Remove the current database */
  60.     GetNumRecs
  61.     if rc ~= 0 then do
  62.         
  63.         Request 'You will lose your current database'LF'Are you sure ?' Gads '_Yes|_No'
  64.         if RC = 1 then New No_Confirm
  65.         else exit
  66.     end
  67.     
  68.     do while ~eof(fp)
  69.         
  70.         /* Read name, fone number and fax numeber */
  71.         name = readln(fp)
  72.          
  73.         if(eof(fp)) then break
  74.         
  75.         fone = readln(fp)
  76.         fax = readln(fp)
  77.         
  78.         /* Add an entry */
  79.         Add_Entry
  80.         /* Put in the name */
  81.         Put_Entry 1 name
  82.         /* Blank out the unneeded fields */
  83.         Put_Entry 2 ''
  84.         Put_Entry 3 ''
  85.         Put_Entry 4 ''
  86.         Put_Entry 5 ''
  87.         Put_Entry 6 ''
  88.         /* And store the fone number and fax */
  89.         Put_Entry 7 fone
  90.         Put_Entry 8 fax
  91.         Set_Type 1 1
  92.         Set_Type 2 2
  93.                 
  94.     end
  95.     
  96.     call Close(fp)
  97.     end
  98.     
  99. else do
  100.     /* We couldn't open the requsted file, display an error */
  101.     Request 'Cant find file' GADS 'Sorry'
  102. end
  103.